package com.gitee.wsl.func.chain

import com.gitee.wsl.func.Function
import com.gitee.wsl.func.InvokeCall

open class Chain<T, R>(
    val filters: List<ChainCall<T,R>>,
    val invoker: Function<T, R>,
):InvokeCall<T,R> {
    private var  pos:Int = -1
    override fun invoke(t: T): R {
        pos++;
        if (pos < filters.size) {
            return filters[pos].call(t,this)
        }
        return invoker.apply(t);
    }
}

interface ChainCall<T,R>{
    fun call(param: T,chain:Chain<T,R>): R
}